package task;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Map;

import org.eclipse.swt.graphics.ImageData;


public class DropOracleSchemas extends DbTask {


	@Override
	public void run(Map<String, String> props) {
		try {
			if (!conn().getMetaData().getDatabaseProductName().toLowerCase().contains("oracle")) {
				System.out.printf("%s only works on oracle db%n", getClass().getName());
				return;
			}
			
			String users = props.get("users");
			String[] userList = users.split(" ");
			
			//DROP user %s cascade;

			for (String user : userList) 
			{
				Statement stmt = conn().createStatement();
				
				String sql;
				sql = String.format("DROP user %s cascade", user);
				stmt.execute(sql);
				System.out.printf("%s%n", sql);
				stmt.close();
				
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public String getDescription() {
		String desc = "Drop one or more users (separate users with space)";
		return desc + "\n" + Arrays.toString(propertyNames());
	}

	@Override
	public ImageData getImageData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String[] propertyNames() {
		String[] props = { "users" };
		return props;
	}
}
